package com.pinc.cpbl;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Menu_Adapter extends BaseAdapter {
	protected ArrayList<menu_class> items;
	protected LayoutInflater inflater;

	public Menu_Adapter(Context context) {
		inflater = LayoutInflater.from(context);
		items = new ArrayList<menu_class>();
	}

	public void addMenuItem(menu_class menu_item)
	{
		items.add(menu_item);
	}

	public View.OnClickListener getClickListener(int position)
	{
		return items.get(position).mListener;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = inflater.inflate(R.layout.menu_item, null);
		((TextView)view.findViewById(R.id.textView_Item)).setText(items.get(position).title);
		return view;
	}

	public static class menu_class{
		private String title;
		private View.OnClickListener mListener;
		public menu_class(String title, View.OnClickListener Listener) {
			super();
			this.title = title;
			this.mListener = Listener;
		}
	}

	public static class integerClickListener implements View.OnClickListener
	{
		private Class<?> which_class;
		private String tag;
		private int value;
		private Context mContext;

		public integerClickListener(Context ctx, Class<?> c, String tag, int value) {
			this.which_class = c;
			this.tag = tag;
			this.value = value;
			this.mContext = ctx;
		}

		@Override
		public void onClick(View v) {
			Bundle bd = new Bundle();
			Intent intent = new Intent(mContext, which_class);
			bd.putInt(tag, value);
			intent.putExtras(bd);
			mContext.startActivity(intent);
		}
	}

	public static class generalClickListener implements View.OnClickListener
	{
		private Class<?> which_class;
		private Context mContext;

		public generalClickListener(Context ctx, Class<?> c) {
			this.mContext = ctx;
			this.which_class = c;
		}

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(mContext, which_class);
			mContext.startActivity(intent);
		}
	}
}
